package org.example.hadoop.service.authorRatingScoreSort;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import org.example.hadoop.domain.AuthorCountBean;
import org.example.hadoop.domain.AuthorRatingScoreAvgBean;

import java.io.IOException;
import java.math.BigDecimal;

/**
 * @author wwy
 * @date 2020-11-10 19:53
 */
public class AuthorRatingScoreSortReducer extends Reducer<AuthorRatingScoreAvgBean, Text, Text, Text> {
    /**
     * k2         v2
     * AuthorRatingScoreAvgBean      余华，aa,bb
     *
     * k3         v3
     * 余华        9.7
     * @param key
     * @param values
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void reduce(AuthorRatingScoreAvgBean key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
        for (Text value : values) {
            //此处为科学计数法转换为普通数字
            context.write(value,new Text(key.getCount()+""));
        }

    }
}
